<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>收银台</title>
    <script src="{{ URL::asset("js/vue.min.js") }}"></script>
    <script src="{{ URL::asset("js/axios.min.js") }}"></script>
</head>
<body><div id="app"></div></body>
{{-- 手机查看错误插件 --}}
{{--<script src="https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js"></script>--}}
<script type="text/javascript">
    // const vConsole = new VConsole();
    let vm = new Vue({
        el: "#app",
        data: {
            load: false,
            aisle: parseInt({{ $aisle }}),
            params: {!! $pay_params !!}
        },
        mounted: function () {
            if (this.aisle === 1) {
                if (typeof WeixinJSBridge === 'undefined') {
                    if (document.addEventListener) {
                        document.addEventListener('WeixinJSBridgeReady', this.jsApiCall, false);
                    } else if (document.attachEvent) {
                        document.attachEvent('WeixinJSBridgeReady', this.jsApiCall());
                        document.attachEvent('onWeixinJSBridgeReady', this.jsApiCall());
                    }
                } else {
                    this.jsApiCall();
                }
            } else {
                // 关闭页面 - 支付宝
                AlipayJSBridge.call('closeWebview');
            }
        },
        methods: {
            jsApiCall: function () {
                this.load = false;
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest',
                    this.params,
                    function (res) {
                        if (res['err_msg'] === 'get_brand_wcpay_request:ok') {
                            // 关闭页面 - 微信
                            WeixinJSBridge.call('closeWindow');
                        } else {
                            axios.get('{!! $cancel_url !!}').then((res)=>{
                                // 关闭页面 - 微信
                                WeixinJSBridge.call('closeWindow');
                            })
                        }
                    }.bind(this)
                );
            }
        }
    })
</script>
</html>
